package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.service.FactoryShiftTimeService;
import com.uwlaser.service.dto.FactoryShiftTimeDto;
import com.uwlaser.service.dto.FactoryShiftTimeQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
* @author huangpan
* @date 2022-12-02
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "班次休息时间管理")
@RequestMapping("/api/factoryShiftTime")
public class FactoryShiftTimeController {

    private final FactoryShiftTimeService factoryShiftTimeService;

    @GetMapping
    @Log("查询班次休息时间")
    @ApiOperation("查询班次休息时间")
    @PreAuthorize("@el.check('factoryShiftTime:list')")
    public ResponseEntity query(FactoryShiftTimeQueryParam query, Pageable pageable){
        return new ResponseEntity<>(factoryShiftTimeService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增班次休息时间")
    @ApiOperation("新增班次休息时间")
    @PreAuthorize("@el.check('factoryShiftTime:add')")
    public ResponseEntity create(@Validated @RequestBody FactoryShiftTimeDto resources){
        return new ResponseEntity<>(factoryShiftTimeService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改班次休息时间")
    @ApiOperation("修改班次休息时间")
    @PreAuthorize("@el.check('factoryShiftTime:edit')")
    public ResponseEntity update(@Validated @RequestBody FactoryShiftTimeDto resources){
        factoryShiftTimeService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除班次休息时间")
    @ApiOperation("删除班次休息时间")
    @PreAuthorize("@el.check('factoryShiftTime:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        factoryShiftTimeService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出班次休息时间")
    @ApiOperation("导出班次休息时间")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('factoryShiftTime:list')")
    public void download(HttpServletResponse response, FactoryShiftTimeQueryParam query) throws IOException {
        factoryShiftTimeService.download(factoryShiftTimeService.queryAll(query), response);
    }*/

}
